<?php
session_start();
if (isset($_POST['op']) && isset($_POST['p']) && isset($_POST['code'])){
    include '../c/config.php';
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
   
   $openid=addslashes(trim($_POST['op']));
   $phone=addslashes(trim($_POST['p']));
   $code=addslashes(trim($_POST['code']));
   $testUrl='https://nc-api-test.51wom.com/api/customerUserMountainClimbing/phoneCheck';
$getUrl=$testUrl.'?phone='.$phone.'&code='.$code;
$getData=json_decode(file_get_contents($getUrl), true);
  if (isset($getData['code'])) {
     if(1 == $getData['code']){

     }else{
        $mysqli->query("insert into sms_log(openid,phone,msg,createtime) values('".$openid."','".$phone."-y','".json_encode($getData, JSON_UNESCAPED_UNICODE)."','".date("Y-m-d H:i:s")."') ");
        echo json_encode(array('s' =>'n' ,'t'=>'sms'));
        exit;
     }
  }else{
    $mysqli->query("insert into sms_log(openid,phone,msg,createtime) values('".$openid."','".$phone."-y','".json_encode($getData, JSON_UNESCAPED_UNICODE)."','".date("Y-m-d H:i:s")."') ");
    echo json_encode(array('s' =>'n' ,'t'=>'sms'));
    exit;
  }
   $getUrl='https://nc-api-test.51wom.com/api/customerUserMountainClimbing/crm-state?phone='.$phone;
   $getData=json_decode(file_get_contents($getUrl), true); 
   
 
   
   $mysqli->query("insert into user_loginreg_log(openid,lei,msg,createtime) values('".$openid."','login','".json_encode($getData, JSON_UNESCAPED_UNICODE)."','".date("Y-m-d H:i:s")."') ");

   $mysqli->query("update zsu_phone_tong set phone='".$phone."' where openid='".$openid."' ");

   if (isset($getData['data']) && 104 == $getData['data']) {
         $mysqli->query("update ".$tableVer."_users set regcode='".$getData['data']."'  where openid='".$openid."' ");
         echo json_encode(array('s' =>'y' ,'t'=>'reg'));
         exit;
   }
   if (NULL == $getData['data'] ) {   
          echo json_encode(array('s' =>'n' ,'t'=>'phone'));
          exit;
   }

   if (isset($getData['data'])) {
      if(101 == $getData['data'] || 102 == $getData['data'] || 103 == $getData['data']){
        $mysqli->query("update ".$tableVer."_users set phone='".$phone."',regcode='".$getData['data']."'  where openid='".$openid."' ");
        echo json_encode(array('s' =>'y' ,'t'=>'gogo'));
        exit;
      }
         
   }
    
    
     
    
    
     
    
    
}
?>
